package com.th.supcom.pds.impl.service.jms;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.ObjectMessage;
import javax.jms.Session;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

public class JmsSendMessageTool
{
    private JmsTemplate m_jmsTemplate;
    private static final Logger LOGGER = LoggerFactory.getLogger (JmsSendMessageTool.class);

    /**
     * 发送消息
     * 
     */
    public void send (String beanIdMt, Object obj)
    {
        LOGGER.info ("发送消息，参数beanIdMt={}，obj={}", new Object[]
        { beanIdMt, obj });
        try
        {
            m_jmsTemplate.send (new MessageCreator ()
            {
                @Override
                public Message createMessage (Session session) throws JMSException
                {
                    ObjectMessage objMessage = session.createObjectMessage ();
                    return objMessage;
                }
            });
        }
        catch (Exception e)
        {
            throw new RuntimeException ("发送消息出错Exception", e);
        }
    }

    // ---getter--setter---//
    public JmsTemplate getJmsTemplate ()
    {
        return m_jmsTemplate;
    }

    public void setJmsTemplate (JmsTemplate jmsTemplate)
    {
        m_jmsTemplate = jmsTemplate;
    }
}
